package com.schd.base.model;

import com.github.wenhao.jpa.Sorts;
import lombok.Data;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;

/**
 * @author 陈刚
 * @version 1.0
 * @project ZNSM
 * @package com.haorui.base.core.model
 * @createDate 2017-08-18 17:30
 * @modfiyDate
 * @function 分页组件
 */
@Data
public class PageModel {
    private Integer pageNum;
    private Integer pageSize;
    private String sortstr;
    public PageRequest pageRequest(){

        if(sortstr==null){
            return new PageRequest(pageNum,pageSize);
        }else{
            Sort sort;
            if(sortstr.startsWith("-")){
                sort=Sorts.builder().desc(sortstr.substring("-".length())).build();
            }else{
                sort=Sorts.builder().asc(sortstr).build();
            }
            return new PageRequest(pageNum,pageSize,sort);
        }

    }
}
